package com.tourism.website.articledisplay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tourism.website.articledisplay.entity.Article;
import com.tourism.website.articledisplay.entity.ArticleImg;
import com.tourism.website.articledisplay.entity.Category;
import com.tourism.website.articledisplay.mapper.ArticleMapper;
import com.tourism.website.articledisplay.service.IArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tourismwebsite.articledisplay.dto.ArticleDTO;
import com.tourismwebsite.articledisplay.dto.ArticleImgDTO;
import com.tourismwebsite.articledisplay.dto.CategoryDTO;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyc
 * @since 2024-06-11
 */
@Mapper(componentModel="spring")
interface MsArticleMapper{
    ArticleDTO ArticleToArticleDTO(Article article);
}

@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {
    @Resource
    MsArticleMapper msArticleMapper;
    @Override
    public ArticleDTO queryArticleContent(Integer articleId) {
        LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Article::getArticleId,articleId);
        wrapper.eq(Article::getStatus,0);
        wrapper.eq(Article::getDelFlag,0);
        wrapper.select(Article::getUserName,Article::getNickName,Article::getCreateTime,Article::getUpdateTime,
                Article::getUserId,Article::getContent);
        Article  article = baseMapper.selectOne(wrapper);
       ArticleDTO articleDTO = msArticleMapper.ArticleToArticleDTO(article);
        return articleDTO;
    }

    @Override
    public ArticleDTO queryArticleNameAndTime(Integer articleId) {
        LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Article::getArticleId,articleId);
        wrapper.eq(Article::getStatus,0);
        wrapper.eq(Article::getDelFlag,0);
        wrapper.select(Article::getTitle,Article::getUpdateTime);
        Article  article = baseMapper.selectOne(wrapper);
        ArticleDTO articleDTO = msArticleMapper.ArticleToArticleDTO(article);
        return articleDTO;
    }
}
